package ar.edu.unicen.pladema.vc1.fractal;

/**
 * Representación del fractal de Mandelbrot.
 * 
 * @author Sebastian Perruolo
 *
 */
public class Fractal {
	private static double REAL_MIN=-1.5;
	private static double REAL_MAX=0.5;
	private static double IMAG_MIN = -1;
	private static double IMAG_MAX = 1;

	private double zoom = 1;
	public int doCount(int x, int y) {
		double dx = (new Double(x)).doubleValue();
		double dy = (new Double(y)).doubleValue();
		double rpart = dx / zoom;
		double ipart = dy / zoom;
		return iterationCount(rpart +REAL_MIN, ipart +IMAG_MIN);
	}
	private static int iterationCount(double realPart, double imagPart) {
		if (IMAG_MAX < imagPart) return -1;
		if (REAL_MAX < realPart) return -1;
		if (IMAG_MIN > imagPart) return -1;
		if (REAL_MIN > realPart) return -1;
		ComplexNumber z0 = new ComplexNumber(realPart,imagPart);
		ComplexNumber zn = new ComplexNumber(0,0);		
		int count = 0;//add by me
		double modulo = zn.module();
		while ((count<255) && ((modulo)<2)) {
			zn = z0.add(ComplexNumber.square(zn));
			modulo = zn.module();
			count++;
		}
		return (count); /// Esta es la variable que vamos a usar para colorear	
	}
	public void setZoom(double zoom) {
		this.zoom = zoom;
	}
}
